package com.wanxi.generictype.superextends;

import java.util.ArrayList;
import java.util.List;

public class Test {
    public void printListExtends(List<? extends Person> list) {
        // 传入的集合元素，只能是Person或Person的子类
        for (Person person : list) {
            person.show();
        }
    }

    public void printListSuper(List<? super Person> list) {
        // Person和person的父类
        for (Object person : list) {
            System.out.println(person.toString());
        }
    }

    public void printListAny(List<?> list) {
        for (Object person : list) {
            System.out.println(person.toString());
        }
    }

    public static void main(String[] args) {
        Test test = new Test();


        // person 的子类
        List<Woman> listWoman = new ArrayList<>();
        listWoman.add(new Woman());
        test.printListExtends(listWoman);

        //person 类
        List<Person> listPerson = new ArrayList<>();
        test.printListExtends(listPerson);
        test.printListSuper(listPerson);

        // 任意 类
        List<Animal> listAnimal = new ArrayList<>();
        listAnimal.add(new Animal());
        test.printListAny(listAnimal);

    }


}
